package dev.ece.core.light;

import org.lwjgl.opengl.GL20;

/**
 * 灯光信息shader locations
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class LightLocationHandler {

	private int enableHandler;
	/**
	 * 光的颜色
	 */
	private int colorHandler;
	/**
	 * 光源位置
	 */
	private int positionHandler;
	/**
	 * 环境光
	 */
	private int ambientHandler;
	/**
	 * 散射光
	 */
	private int diffuseHandler;
	/**
	 * 高光
	 */
	private int specularHandler;
	
	/**
	 * 聚光灯方向
	 */
	private int directionHandler;
	
	private int spotExponentHandler;  
	
	private int spotCutoffHandler; // (range: [0.0,90.0], 180.0)
	
	private int spotCosCutoffHandler; // (range: [1.0,0.0],-1.0)
	
	private int constantAttenuationHandler;
	
	private int linearAttenuationHandler;
	
	private int quadraticAttenuationHandler;  
	
	private LightLocationHandler() {}
	
	public static LightLocationHandler newInstance(int program, String prefix) {
		LightLocationHandler handler = new LightLocationHandler();
		handler.enableHandler = GL20.glGetUniformLocation(program, prefix.concat("enable"));
		handler.colorHandler = GL20.glGetUniformLocation(program, prefix.concat("color"));
		handler.positionHandler = GL20.glGetUniformLocation(program, prefix.concat("position"));
		handler.ambientHandler = GL20.glGetUniformLocation(program, prefix.concat("ambient"));
		handler.diffuseHandler = GL20.glGetUniformLocation(program, prefix.concat("diffuse"));
		handler.specularHandler = GL20.glGetUniformLocation(program, prefix.concat("specular"));
		handler.directionHandler = GL20.glGetUniformLocation(program, prefix.concat("direction"));
		handler.spotExponentHandler = GL20.glGetUniformLocation(program, prefix.concat("spotExponent"));
		handler.spotCutoffHandler = GL20.glGetUniformLocation(program, prefix.concat("spotCutoff"));
		handler.spotCosCutoffHandler = GL20.glGetUniformLocation(program, prefix.concat("spotCosCutoff"));
		handler.constantAttenuationHandler = GL20.glGetUniformLocation(program, prefix.concat("constantAttenuation"));
		handler.linearAttenuationHandler = GL20.glGetUniformLocation(program, prefix.concat("linearAttenuation"));
		handler.quadraticAttenuationHandler = GL20.glGetUniformLocation(program, prefix.concat("quadraticAttenuation"));
		return handler;
	}

	public void glUniformLight(Light light) {
		light.glUniformLight(this);
	}
	
	protected void setEnableHandler(int enableHandler) {
		this.enableHandler = enableHandler;
	}

	protected void setPositionHandler(int positionHandler) {
		this.positionHandler = positionHandler;
	}

	protected void setAmbientHandler(int ambientHandler) {
		this.ambientHandler = ambientHandler;
	}

	protected void setDiffuseHandler(int diffuseHandler) {
		this.diffuseHandler = diffuseHandler;
	}

	protected void setSpecularHandler(int specularHandler) {
		this.specularHandler = specularHandler;
	}

	protected void setDirectionHandler(int directionHandler) {
		this.directionHandler = directionHandler;
	}

	protected void setSpotExponentHandler(int spotExponentHandler) {
		this.spotExponentHandler = spotExponentHandler;
	}

	protected void setSpotCutoffHandler(int spotCutoffHandler) {
		this.spotCutoffHandler = spotCutoffHandler;
	}

	protected void setSpotCosCutoffHandler(int spotCosCutoffHandler) {
		this.spotCosCutoffHandler = spotCosCutoffHandler;
	}

	protected void setConstantAttenuationHandler(int constantAttenuationHandler) {
		this.constantAttenuationHandler = constantAttenuationHandler;
	}

	protected void setLinearAttenuationHandler(int linearAttenuationHandler) {
		this.linearAttenuationHandler = linearAttenuationHandler;
	}

	protected void setQuadraticAttenuationHandler(int quadraticAttenuationHandler) {
		this.quadraticAttenuationHandler = quadraticAttenuationHandler;
	}

	public int getEnableHandler() {
		return enableHandler;
	}

	public int getPositionHandler() {
		return positionHandler;
	}

	public int getAmbientHandler() {
		return ambientHandler;
	}

	public int getDiffuseHandler() {
		return diffuseHandler;
	}

	public int getSpecularHandler() {
		return specularHandler;
	}

	public int getDirectionHandler() {
		return directionHandler;
	}

	public int getSpotExponentHandler() {
		return spotExponentHandler;
	}

	public int getSpotCutoffHandler() {
		return spotCutoffHandler;
	}

	public int getSpotCosCutoffHandler() {
		return spotCosCutoffHandler;
	}

	public int getConstantAttenuationHandler() {
		return constantAttenuationHandler;
	}

	public int getLinearAttenuationHandler() {
		return linearAttenuationHandler;
	}

	public int getQuadraticAttenuationHandler() {
		return quadraticAttenuationHandler;
	}

	public int getColorHandler() {
		return colorHandler;
	}

	public void clearup() {
		GL20.glDeleteShader(enableHandler);
		GL20.glDeleteShader(colorHandler);
		GL20.glDeleteShader(positionHandler);
		GL20.glDeleteShader(ambientHandler);
		GL20.glDeleteShader(diffuseHandler);
		GL20.glDeleteShader(specularHandler);
		GL20.glDeleteShader(directionHandler);
		GL20.glDeleteShader(spotExponentHandler);
		GL20.glDeleteShader(spotCutoffHandler);
		GL20.glDeleteShader(spotCosCutoffHandler);
		GL20.glDeleteShader(constantAttenuationHandler);
		GL20.glDeleteShader(linearAttenuationHandler);
		GL20.glDeleteShader(quadraticAttenuationHandler);
	}
	
}
